<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>XJIOTKit 使用 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="XJIOTKit 使用version: 0.2.25导入SDK1234pod &amp;apos;XJIOTKit&amp;apos;# XJIOTUtil 可选 集成了几种配网工具 乐鑫(ESPTouch)、庆科(EasyLink)、awspod &amp;apos;XJIOTUtil&amp;apos; 初始化1[XJIOTKitApi startWithDevelopKey:APP_DEVELOP_KEY developS">
<meta name="keywords" content="xjiang,iOS,XJIOTKit,使用文档">
<meta property="og:type" content="article">
<meta property="og:title" content="XJIOTKit 使用">
<meta property="og:url" content="http://yoursite.com/2019/04/12/XJIOTKit-使用/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="XJIOTKit 使用version: 0.2.25导入SDK1234pod &amp;apos;XJIOTKit&amp;apos;# XJIOTUtil 可选 集成了几种配网工具 乐鑫(ESPTouch)、庆科(EasyLink)、awspod &amp;apos;XJIOTUtil&amp;apos; 初始化1[XJIOTKitApi startWithDevelopKey:APP_DEVELOP_KEY developS">
<meta property="og:locale" content="中文">
<meta property="og:updated_time" content="2019-04-16T06:35:09.687Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="XJIOTKit 使用">
<meta name="twitter:description" content="XJIOTKit 使用version: 0.2.25导入SDK1234pod &amp;apos;XJIOTKit&amp;apos;# XJIOTUtil 可选 集成了几种配网工具 乐鑫(ESPTouch)、庆科(EasyLink)、awspod &amp;apos;XJIOTUtil&amp;apos; 初始化1[XJIOTKitApi startWithDevelopKey:APP_DEVELOP_KEY developS">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-XJIOTKit-使用" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/04/12/XJIOTKit-使用/" class="article-date">
  <time datetime="2019-04-12T02:28:28.000Z" itemprop="datePublished">2019-04-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      XJIOTKit 使用
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="XJIOTKit-使用"><a href="#XJIOTKit-使用" class="headerlink" title="XJIOTKit 使用"></a>XJIOTKit 使用</h2><h6 id="version-0-2-25"><a href="#version-0-2-25" class="headerlink" title="version: 0.2.25"></a>version: 0.2.25</h6><h4 id="导入SDK"><a href="#导入SDK" class="headerlink" title="导入SDK"></a>导入SDK</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">pod &apos;XJIOTKit&apos;</span><br><span class="line"></span><br><span class="line"># XJIOTUtil 可选 集成了几种配网工具 乐鑫(ESPTouch)、庆科(EasyLink)、aws</span><br><span class="line">pod &apos;XJIOTUtil&apos;</span><br></pre></td></tr></table></figure>
<h4 id="初始化"><a href="#初始化" class="headerlink" title="初始化"></a>初始化</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[XJIOTKitApi startWithDevelopKey:APP_DEVELOP_KEY developSecret:APP_DEVELOP_SECRET source:APP_Source];</span><br></pre></td></tr></table></figure>
<h4 id="获取到-userId-后兑换-userSecret"><a href="#获取到-userId-后兑换-userSecret" class="headerlink" title="获取到 userId 后兑换 userSecret"></a>获取到 userId 后兑换 userSecret</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[XJIOTKitApi userSecretIfNeedWithUserId:userId response:^(BOOL userInvalid, NSString *userSecret, NSError *error) &#123;</span><br><span class="line"></span><br><span class="line">&#125;];</span><br></pre></td></tr></table></figure>
<h4 id="启动-XJDeviceManager"><a href="#启动-XJDeviceManager" class="headerlink" title="启动 XJDeviceManager"></a>启动 XJDeviceManager</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[XJDeviceManager shared].dataSource = self; // 设置数据源代理</span><br><span class="line">[[XJDeviceManager shared] startWithUserId:userId];</span><br></pre></td></tr></table></figure>
<h4 id="启动-XJMQTTManager"><a href="#启动-XJMQTTManager" class="headerlink" title="启动 XJMQTTManager"></a>启动 XJMQTTManager</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[[XJMQTTManager sharedInstanced] connectWithUserId:userId userSecret:userSecret developKey:APP_DEVELOP_KEY result:^(NSError *error) &#123;</span><br><span class="line">        if (error) &#123;</span><br><span class="line">            NSLog(@&quot;mqtt Error [%@]&quot;, error.description);</span><br><span class="line">        &#125;</span><br><span class="line">&#125;];</span><br></pre></td></tr></table></figure>
<h4 id="建立设备模型"><a href="#建立设备模型" class="headerlink" title="建立设备模型"></a>建立设备模型</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">/** 电风扇设备 属性字段名要求与协议上定义的一致 */</span><br><span class="line">@interface FanDevice : XJDevice</span><br><span class="line"></span><br><span class="line">/// 电源开关</span><br><span class="line">@property (nonatomic, strong) XJDeviceValue *PowerSwitch;</span><br><span class="line">/// 风速</span><br><span class="line">@property (nonatomic, strong) XJDeviceValue *Speed;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure>
<h4 id="完成数据源代理-XJDeviceManagerDataSource"><a href="#完成数据源代理-XJDeviceManagerDataSource" class="headerlink" title="完成数据源代理 XJDeviceManagerDataSource"></a>完成数据源代理 XJDeviceManagerDataSource</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#pragma mark - XJDeviceManagerDataSource</span><br><span class="line"></span><br><span class="line">- (Class)deviceManager:(XJDeviceManager *)manager subDeviceClassWithProductKey:(NSString *)productKey &#123;</span><br><span class="line">	if ([productKey isEqualToString:@&quot;abcdefg&quot;])</span><br><span class="line">	    return FanDevice.class;</span><br><span class="line">	...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="下发控制"><a href="#下发控制" class="headerlink" title="下发控制"></a>下发控制</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">/// 设备列表获取的设备 _device</span><br><span class="line"></span><br><span class="line">/// 下发风速控制为1档</span><br><span class="line">[_device sendControlWithKey:@&quot;Speed&quot; value:@&quot;1&quot; certainDeliver:YES result:^(uint32_t msgID, BOOL delivered, NSError * _Nullable error) &#123;</span><br><span class="line">	if (delivered) &#123; /// 下发成功</span><br><span class="line">	</span><br><span class="line">	&#125;</span><br><span class="line">&#125;];</span><br></pre></td></tr></table></figure>
<h4 id="设备列表变化和设备状态变化"><a href="#设备列表变化和设备状态变化" class="headerlink" title="设备列表变化和设备状态变化"></a>设备列表变化和设备状态变化</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">//设备列表</span><br><span class="line">XJDeviceManager.shared.devices</span><br><span class="line"></span><br><span class="line">// 设备列表和设备状态改变的代理</span><br><span class="line">XJDeviceManagerDelegate</span><br><span class="line"></span><br><span class="line">example:</span><br><span class="line"></span><br><span class="line">#pragma mark - XJDeviceManagerDelegate</span><br><span class="line"></span><br><span class="line">- (void)deviceManager:(XJDeviceManager *)manager didChange:(__kindof XJDevice *)device isNew:(BOOL)isNew atIndex:(NSUInteger)index &#123;</span><br><span class="line">    if (isNew) &#123; /// 设备列表增加了设备</span><br><span class="line">        [self.collectionView performBatchUpdates:^&#123;</span><br><span class="line">            if (index == 0) &#123; // 没有数据源的时候不能调用 insertItemsAtIndexPaths</span><br><span class="line">                [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:XJMainDeviceSectionDevice]];</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:XJMainDeviceSectionDevice]]];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; completion:^(BOOL finished) &#123;</span><br><span class="line"></span><br><span class="line">        &#125;];</span><br><span class="line">        </span><br><span class="line">    &#125; else &#123; ///设备状态发生了变化</span><br><span class="line">        XJMainDeviceCollectionViewCell *cell = (XJMainDeviceCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:XJMainDeviceSectionDevice]];</span><br><span class="line">        [self configCell:cell forDevice:device];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)deviceManager:(XJDeviceManager *)manager didRemove:(NSArray&lt;__kindof XJDevice *&gt; *)devices atIndexSet:(NSIndexSet *)indexSet &#123;</span><br><span class="line">    [self.collectionView performBatchUpdates:^&#123;</span><br><span class="line">        [self.collectionView deleteItemsAtIndexPaths:[manager indexPathsWithIndexSet:indexSet inSection:XJMainDeviceSectionDevice]];</span><br><span class="line">    &#125; completion:^(BOOL finished) &#123;</span><br><span class="line"></span><br><span class="line">    &#125;];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/04/12/XJIOTKit-使用/" data-id="cjujetss200011lrjd1qkra57" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/XJIOTKit/">XJIOTKit</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/iOS/">iOS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/xjiang/">xjiang</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/使用文档/">使用文档</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
  
    <a href="/2019/04/11/新用户注册推送到中心/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">新用户注册推送到中心</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/XJIOTKit/">XJIOTKit</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/iOS/">iOS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xjiang/">xjiang</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/使用文档/">使用文档</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/XJIOTKit/" style="font-size: 10px;">XJIOTKit</a> <a href="/tags/iOS/" style="font-size: 10px;">iOS</a> <a href="/tags/xjiang/" style="font-size: 10px;">xjiang</a> <a href="/tags/使用文档/" style="font-size: 10px;">使用文档</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/04/12/XJIOTKit-使用/">XJIOTKit 使用</a>
          </li>
        
          <li>
            <a href="/2019/04/11/新用户注册推送到中心/">新用户注册推送到中心</a>
          </li>
        
          <li>
            <a href="/2019/04/11/开发者账号秘钥验证，并获取token/">开发者账号秘钥验证，并获取token</a>
          </li>
        
          <li>
            <a href="/2019/04/11/小匠云平台物联网开发套件iotkit（Android）使用手册/">小匠云平台物联网开发套件iotkit（Android）使用手册</a>
          </li>
        
          <li>
            <a href="/2019/03/04/hello-world/">Hello World</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 zt.cfvli<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>